home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / xmaxima / server.lisp < prev   
Encoding:
Text File  |  2003-02-09  |  2.1 KB  |  75 lines

  1.  
  2. ;; very simple server started on port
  3.  
  4. (and (find-package "MAXIMA") (push :maxima *features*))
  5.  
  6. #+maxima
  7. (in-package "MAXIMA")
  8.  
  9.  
  10.  
  11. (defun user::setup ( port &optional (host "localhost"))
  12.   (let* ((sock (open-socket host port)))
  13.     (setq me sock)
  14.    #+gcl (setq si::*sigpipe-action* 'si::bye)
  15.     (setq *socket-connection* sock)
  16.     (setq *standard-input* sock)
  17.     (setq *standard-output* sock)
  18.     (setq *error-output* sock)
  19.     (setq *terminal-io* sock)
  20.     (format t "pid=~a~%"        (getpid))
  21.     (force-output sock)
  22.     (setq *debug-io* sock)
  23.     (values)
  24.     ))
  25.  
  26. ;;; from CLOCC: <http://clocc.sourceforge.net>
  27. (defun open-socket (host port &optional bin)
  28.   "Open a socket connection to HOST at PORT."
  29.   (declare (type (or integer string) host) (fixnum port) (type boolean bin))
  30.   (let ((host (etypecase host
  31.                 (string host)
  32.                 (integer (hostent-name (resolve-host-ipaddr host))))))
  33.     #+allegro (socket:make-socket :remote-host host :remote-port port
  34.                                   :format (if bin :binary :text))
  35.     #+clisp (socket-connect port host :element-type
  36.                                  (if bin '(unsigned-byte 8) 'character))
  37.  
  38.     #+cmu (sys:make-fd-stream (ext:connect-to-inet-socket host port)
  39.                               :input t :output t :element-type
  40.                               (if bin '(unsigned-byte 8) 'character))
  41.     #+gcl (si::socket port :host host)
  42.     #+lispworks (comm:open-tcp-stream host port :direction :io :element-type
  43.                                       (if bin 'unsigned-byte 'base-char))
  44.     #-(or allegro clisp cmu gcl lispworks)
  45.     (error 'not-implemented :proc (list 'open-socket host port bin))))
  46.  
  47.  
  48.  
  49. #+maxima
  50. (progn
  51. (setq $in_netmath t)
  52. (setq $show_openplot nil))
  53.  
  54. #+clisp
  55. (defun getpid ( &aux tem)
  56.   
  57.   (cond ((fboundp 'sys::program-id)
  58.      (sys::program-id))
  59.                     ; ;under windows above does not work.
  60.     ((consp (setq tem (errset (system::getenv "PID"))))
  61.      (read-from-string (car tem)))
  62.     (t (format t "using fake value for pid") -1))
  63.   )
  64. #+cmu
  65. (defun getpid () (unix:unix-getpid))
  66.  
  67. #+(or gcl clisp cmu)
  68. (defun xchdir (w)
  69.   #+clisp (cd w)
  70.   #+gcl (si::chdir w)
  71.   #+cmu (unix::unix-chdir w)
  72.   )
  73.  
  74.   
  75.